package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try(
                Connection conn = DBUtil.getConnection()
                ){
            Statement stmt = conn.createStatement();//创建连接对象
            String sql ="SELECT t.name,t.salary,t.title,c.name,c.floor  " +
                    "FROM teacher t,class c  " +
                    "WHERE t.id=c.teacher_id  " +
                    "AND t.name='王克晶'";
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next())
            {
                String name = rs.getString(1);
                int salary = rs.getInt(2);
                String title = rs.getString(3);
                String className = rs.getString(4);
                int floor = rs.getInt(5);
                System.out.println(name+" "+salary+" "+title+" "+className+" "+floor);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
